package com.ruoyi.web.controller.website;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.module.domain.ExamQuestions;
import com.ruoyi.module.service.IExamQuestionsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考试题目Controller
 *
 * @author fubojin
 * @date 2025-03-05
 */
@RestController
@RequestMapping("/website/examQuestions")
public class WebExamQuestionsController extends BaseController
{
    @Autowired
    private IExamQuestionsService examQuestionsService;

    /**
     * 查询考试题目列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ExamQuestions examQuestions)
    {
        startPage();
        List<ExamQuestions> list = examQuestionsService.selectExamQuestionsList(examQuestions);
        return getDataTable(list);
    }

    /**
     * 获取不同类型的题目
     * examType 题目类型（1-初级，3-高级）
     * choice 单选题数量
     * choiceRepeat 多选题数量
     * judge 判断题数量
     */
    @GetMapping("/listCategory")
    public AjaxResult listCategory(@RequestParam Integer examType,Integer choice,Integer choiceRepeat,Integer judge){
        return success(examQuestionsService.selectQuestionsCategoryList(examType,choice,choiceRepeat,judge));
    }

    /**
     * 导出考试题目列表
     */
    @Log(title = "考试题目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamQuestions examQuestions)
    {
        List<ExamQuestions> list = examQuestionsService.selectExamQuestionsList(examQuestions);
        ExcelUtil<ExamQuestions> util = new ExcelUtil<ExamQuestions>(ExamQuestions.class);
        util.exportExcel(response, list, "考试题目数据");
    }

    /**
     * 获取考试题目详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(examQuestionsService.selectExamQuestionsById(id));
    }

    /**
     * 新增考试题目
     */
    @Log(title = "考试题目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamQuestions examQuestions)
    {
        return toAjax(examQuestionsService.insertExamQuestions(examQuestions));
    }

    /**
     * 修改考试题目
     */
    @Log(title = "考试题目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamQuestions examQuestions)
    {
        return toAjax(examQuestionsService.updateExamQuestions(examQuestions));
    }

    /**
     * 删除考试题目
     */
    @Log(title = "考试题目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(examQuestionsService.deleteExamQuestionsByIds(ids));
    }
}
